import java.io.*;
import java.net.*;

public class PseudoPing {
    public static void main(String args[]) {
	for (int i = 0; i<1000; i++) {
	    try {

		Socket t = new Socket(args[0], i);
		DataInputStream dis = new DataInputStream(t.getInputStream());
		PrintStream ps = new PrintStream(t.getOutputStream());
		ps.println("Hello");
		String str = dis.readLine();
		System.out.println("PORT="+i) ;
		System.out.println(str) ;
		//if (str.equals("Hello"))
		//  System.out.println("Alive!") ;
		//else
		//  System.out.println("Dead or echo port not responding");              
		t.close();
	    }
	    catch (IOException e) {
		e.printStackTrace();
		System.out.println("PORT: "+ i +" is not alive");
	    }
	}
    }
}


